<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <!-- <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="配置">
                <a-input v-model="queryParam.search" placeholder=""/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => this.queryParam = {}">重置</a-button>
              </span>
            </a-col>
          </a-row> -->
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" icon="plus" @click="toAdd">新增</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <s-table
        ref="table"
        :columns="columns"
        :data="loadData"
        :row-key="(record)=>record.id"
        :showPagination="true"
      >
        <span slot="code" slot-scope="text">
          <img :src="text" style="width:80px;height:80px;" />
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="toDetail(record)">编辑</a>
            <a-divider type="vertical" />
            <a-popconfirm placement="topLeft" ok-text="是" cancel-text="否" @confirm="toDelete(record)">
              <template slot="title">
                <p>确定要删除这条记录吗？</p>
              </template>
              <!-- <a-button>TL</a-button> -->
              <a>删除</a>
            </a-popconfirm>
          </template>
        </span>
      </s-table>
      <detail-form :visible="detailVisible" :model="this.model" @cancel="()=>{this.detailVisible=false}" @ok="modalOk" />
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { getConfigLists, deleteConfig } from '@/api/manage'
import { STable } from '@/components'
import DetailForm from './Detail'
import { notification } from 'ant-design-vue'
export default {
  name: 'ConfigLists',
  data () {
    return {
      model: {},
      detailVisible: false,
      queryParam: {},
      departmentList: [],
      columns: [
        {
          title: '#',
          dataIndex: 'id'
        },
        {
          title: '短信模板',
          dataIndex: 'smsContent'
        },
        {
          title: '调试模式',
          dataIndex: 'isDebug',
          customRender: (text) => { return (text === 1) ? '是' : '否' }
        },
        {
          title: '审核开启',
          dataIndex: 'mustCheck',
          customRender: (text) => { return (text === 1) ? '是' : '否' }
        },
        {
          title: '登录开启',
          dataIndex: 'mustLogin',
          customRender: (text) => { return (text === 1) ? '是' : '否' }
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '150px',
          scopedSlots: { customRender: 'action' }
        }
      ],
      loadData: parameter => {
        // 不要在这里修改分页大小，STable已经写死默认每一页10条
        const cParameter = { pageSize: parameter.pageSize, pageNum: parameter.pageNo }
        const requestParameter = Object.assign({}, cParameter, this.queryParam)
        return getConfigLists(requestParameter).then(res => {
          this.departmentList = res.data
          return {
            data: res.data,
            totalCount: parseInt(res.headers['x-count']),
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize
          }
        })
      }
    }
  },
  components: {
    STable,
    DetailForm
  },
  created () {
    // this.init()
  },
  methods: {
    modalOk () {
      this.model = {}
      this.detailVisible = false
      this.$refs.table.refresh(false)
    },
    init () {
      getConfigLists({ pageSize: this.pageSize, pageNum: this.pageNo }).then(res => {
        this.departmentList = res.data
        console.log(this.departmentList)
      })
    },
    toAdd () {
      this.model = {}
      this.detailVisible = true
    },
    toDetail (record) {
      this.model = record
      this.detailVisible = true
    },
    toDelete (record) {
      deleteConfig(record.id).then(res => {
        notification.success({
          message: '提示',
          description: '删除成功'
        })
        this.$refs.table.refresh(false)
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
